package cmd

import (
	"devops-tools/config"
	"devops-tools/httpd"
	"fmt"
	"github.com/spf13/cobra"
	"net/http"
)

var (
	serveCmd = &cobra.Command{
		Use:   "server",
		Short: "启动 devops-tools 服务 $ devops-tools serves",
		Long: `使用默认配置启动 devops-tools 服务的操作命令:

$ devops-tools server

定制化服务命令行启动参数参考`,
		Run: func(_ *cobra.Command, _ []string) {
			fmt.Println("服务启动成功,port:", config.GetConfig().Server.Port)
			http.HandleFunc("/start", httpd.StartServer)
			http.HandleFunc("/monitor", httpd.MonitorData)
			http.ListenAndServe(":"+config.GetConfig().Server.Port, nil)
		},
	}
)

func init() {
	rootCmd.AddCommand(serveCmd)
}
